#!/bin/bash
#监控系统内存和交换分区使用情况
#/shell05/free.sh
#取当前时间
date >> /tmp/date.txt
#取物理内存free值
echo "Mem-free:`free -m | grep Mem | awk '{print $4}'`M" >> /tmp/mem-free.txt
#取缓冲区free值
echo "buffers/cache-free:`free -m | grep - | awk '{print $4}'`M" >> /tmp/buffers-free.txt
#取Swap区free值
echo "Swap-free:`free -m | grep Swap | awk '{print $4}'`M" >> /tmp/swap-free.txt
#将时间与相关数据重新写入新文件
paste /tmp/date.txt /tmp/mem-free.txt /tmp/buffers-free.txt /tmp/swap-free.txt > /tmp/free.txt
#发送监控邮件
mail -s "内存监控报告" root@localhost < /tmp/free.txt